package com.xysd.express.activity;

import android.util.Log;
import android.widget.TextView;

import com.google.gson.Gson;
import com.xysd.express.R;
import com.xysd.express.base.BaseActivity;
import com.xysd.express.bean.OrderDetailsObj;
import com.xysd.express.util.JSONParser;
import com.xysd.express.util.LoadingDialogUtils;
import com.xysd.express.util.ToastUtil;
import com.xysd.express.util.http.HttpCallBack;
import com.xysd.express.util.http.HttpUtil;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

@ContentView(R.layout.activity_order_details)
public class OrderDetailsActivity extends BaseActivity {

    @ViewInject(R.id.ststus_tv)
    private TextView ststus_tv;
    @ViewInject(R.id.payinfo_tv)
    private TextView payinfo_tv;
    @ViewInject(R.id.weight_tv)
    private TextView weight_tv;
    @ViewInject(R.id.worthy_tv)
    private TextView worthy_tv;
    @ViewInject(R.id.distance_tv)
    private TextView distance_tv;
    @ViewInject(R.id.company_tv)
    private TextView company_tv;
    @ViewInject(R.id.adds_send_tv)
    private TextView adds_send_tv;
    @ViewInject(R.id.name_tel_send_tv)
    private TextView name_tel_send_tv;
    @ViewInject(R.id.adds_receive_tv)
    private TextView adds_receive_tv;
    @ViewInject(R.id.name_tel_receive_tv)
    private TextView name_tel_receive_tv;
    @ViewInject(R.id.future_price_tv)
    private TextView future_price_tv;
    @ViewInject(R.id.order_price_tv)
    private TextView order_price_tv;
    @ViewInject(R.id.pay_price_tv)
    private TextView pay_price_tv;
    @ViewInject(R.id.ordernum_tv)
    private TextView ordernum_tv;
    @ViewInject(R.id.user_time_tv)
    private TextView user_time_tv;
    @ViewInject(R.id.pay_time_tv)
    private TextView pay_time_tv;
    @ViewInject(R.id.cancle_time_tv)
    private TextView cancle_time_tv;


    private long id;
    private OrderDetailsObj.OrderDetails orderData;

    @Override
    protected void init() {
        setTitleBar("订单详情");
        id = getIntent().getLongExtra("id", 0);
        getData();
    }

    private void getData() {
        LoadingDialogUtils.createLoadingDialog(mActivity).show();
        HttpUtil.getOrderDetails(id, new HttpCallBack() {
            @Override
            public void onSuccess(String result) {
                LoadingDialogUtils.closeLoadingDialog();
                Log.i("订单详情", result);
                String code = JSONParser.getStringFromJsonString("Status", result);
                String msg = JSONParser.getStringFromJsonString("Msg", result);
                if ("0".equals(code)) {
                    OrderDetailsObj obj = new Gson().fromJson(result, OrderDetailsObj.class);
                    orderData = obj.Data;
                    setView();
                } else {
                    ToastUtil.show(msg);
                }
            }

            @Override
            public void onFailure(String error) {
                LoadingDialogUtils.closeLoadingDialog();
                Log.e("订单详情", error);
            }
        });
    }

    private void setView() {
        ststus_tv.setText(orderData.OrderStatusDescription);
        payinfo_tv.setText("实际支付" + orderData.OrderAmount + "(" + orderData.ProfileInfo.VehicleTypeName + ")");
        weight_tv.setText(orderData.ProfileInfo.CargoWeight + "kg");
        worthy_tv.setText(orderData.ProfileInfo.CargoPrice + "元");
        distance_tv.setText(orderData.ProfileInfo.TotalDistance + "km");
        company_tv.setText(orderData.ProfileInfo.CompanyName);
        adds_send_tv.setText(orderData.ProfileInfo.ShipAddress);
        name_tel_send_tv.setText(orderData.ProfileInfo.ShipperContactName + "  " + orderData.ProfileInfo.ShipperMobile);
        adds_receive_tv.setText(orderData.ProfileInfo.ReceiveAddress);
        name_tel_receive_tv.setText(orderData.ProfileInfo.ReceiverContactName + "  " + orderData.ProfileInfo.ReceiverMobile);
        future_price_tv.setText(orderData.ProfileInfo.FuturePrice + "元");
        order_price_tv.setText(orderData.OrderAmount + "元");
        pay_price_tv.setText(orderData.OrderAmount + "元");
        ordernum_tv.setText(orderData.Id + "");
        user_time_tv.setText(orderData.ServiceDate);
        pay_time_tv.setText(orderData.PayDate);
        cancle_time_tv.setText(orderData.CloseDate);

    }
}
